package com.ruoyi.develop.lnShebei.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.develop.lnShebei.domain.LnShebei;
import com.ruoyi.develop.lnShebei.service.ILnShebeiService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备Controller
 * @author qh
 * @date 2024-07-21
 */
@RestController
@RequestMapping("/lnShebei/lnShebei")
public class LnShebeiController extends BaseController {
    @Autowired
    private ILnShebeiService lnShebeiService;

    /**
     * 查询设备列表
     */
    @PreAuthorize("@ss.hasPermi('develop:LnShebei:query')")
    @GetMapping("/list")
    public TableDataInfo list(LnShebei entity) {
        startPage();
        List<LnShebei> list = lnShebeiService.selectList(entity);
        return getDataTable(list);
    }

    /**
     * 导出设备列表
     */
    @PreAuthorize("@ss.hasPermi('develop:LnShebei:export')")
    @Log(title = "设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LnShebei entity) {
        List<LnShebei> list = lnShebeiService.selectList(entity);
        ExcelUtil<LnShebei> util = new ExcelUtil<LnShebei>(LnShebei. class);
        util.exportExcel(response, list, "设备数据");
    }

    /**
     * 获取设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('develop:LnShebei:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(lnShebeiService.selectById(id));
    }

    /**
     * 新增设备
     */
    @PreAuthorize("@ss.hasPermi('develop:LnShebei:add')")
    @Log(title = "设备", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody LnShebei entity) {
        return toAjax(lnShebeiService.insert(entity));
    }

    /**
     * 修改设备
     */
    @PreAuthorize("@ss.hasPermi('develop:LnShebei:edit')")
    @Log(title = "设备", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody LnShebei entity) {
        return toAjax(lnShebeiService.update(entity));
    }

    /**
     * 删除设备
     */
    @PreAuthorize("@ss.hasPermi('develop:LnShebei:remove')")
    @Log(title = "设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(lnShebeiService.deleteByIds(ids));
    }

    /**
     * 设备审核
     */
    @PreAuthorize("@ss.hasPermi('develop:LnShebei:remove')")
    @Log(title = "设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/shenhe/{id}")
    public AjaxResult shenhe(@PathVariable String id) {
        return toAjax(lnShebeiService.shenhe(id));
    }
}
